package com.woniuxy.controller;

import cn.hutool.cache.CacheUtil;
import com.woniuxy.entity.dto.system.DeptDTO;
import com.woniuxy.entity.po.system.Dept;
import com.woniuxy.service.DeptService;
import com.woniuxy.util.CodeUtil;
import com.woniuxy.util.PageParam;
import com.woniuxy.util.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dept")
@AllArgsConstructor
public class DeptController {
    private DeptService deptService;
    private CodeUtil codeUtil;
    /**
     * 查询所有的dept数据，带到页面回显（分页回显）
     * @return
     */
    @PostMapping("/queryAll")
    public ResponseData<?> queryAll(@RequestBody PageParam<DeptDTO> pageParam){
        return deptService.queryAll(pageParam);
    }
    @GetMapping("/queryIdInfo/{id}")
    public ResponseData<?> queryIdInfo(@PathVariable("id") Long id){
        return deptService.queryIdInfo(id);
    }
    @GetMapping("/deleteDept/{id}")
    public ResponseData<?> deleteDept(@PathVariable("id")Long id){
        Integer integer = deptService.deleteDept(id);
        return ResponseData.ok(integer);
    }
    @PostMapping("/batchDeleteDept")
    public ResponseData<?> batchDeleteDept(@RequestBody List<Long> ids){
        deptService.batchDeleteDept(ids);
        return ResponseData.ok();
    }
    @PostMapping("/addDept")
    public ResponseData<?> addDept(@RequestBody DeptDTO deptDTO){
        deptService.addDept(deptDTO);
        return ResponseData.ok();
    }
    @PostMapping("/updateDept")
    public ResponseData<?> updateDept(@RequestBody DeptDTO deptDTO){
        deptService.updateDept(deptDTO);
        return ResponseData.ok();
    }
    @GetMapping("/queryDept")
    public ResponseData<?> queryDept(){
        return ResponseData.ok(deptService.queryDept());
    }
    @GetMapping("/getCode")
    public ResponseData<?> getCode() {
        String s = codeUtil.generateRegularCode("DEPT");
        return ResponseData.ok(s);
    }

}
